<include file="../Address/header"/>
<body>
<div class="wraper">
    <div class="load">
        <img class="load-bee" src="/assets/base/repair/images/load-bee.png"/>
    </div>
    <div class="top">
        <p>
            <a href="javascript:history.back(-1)" class="iconfont icon-zuo fl-left"></a>
            <if condition="$picked neq 1">
                地址管理
                <else/>
                联系方式管理
            </if>
            <a href="{BEESCRM::U('base/center/center',array('account_id'=>$account_id))}"
               class="iconfont icon-shouye fl-right"></a>
        </p>
    </div>
    <p class="title">姓名</p>
    <p class="form-box">
        <input class="input" value="{BEESCRM:$data.real_name}" id="real_name"/>
    </p>
    <p class="title">联系方式</p>
    <p class="form-box">
        <input class="input" value="{BEESCRM:$data.mobile}" id="mobile"/>
    </p>

    <if condition="$picked eq 0">
        <p class="title">所在省</p>
        <p class="form-box">
            <select class="select" id="province">
                <option value="0">请选择省份</option>
                <volist name="province" id="vo">
                    <option value="{BEESCRM:$vo.area_id}"
                    <if condition="$data['province_id'] eq $vo['area_id']"> selected="selected"</if>
                    >{BEESCRM:$vo.area_name}</option>
                </volist>
            </select>
            <span class="triangle"></span>
        </p>

        <p class="title">所在市</p>
        <p class="form-box">
            <select class="select" id="city">
                <option value="0">请选择城市</option>
                <volist name="city" id="vo">
                    <option value="{BEESCRM:$vo['area_id']}"
                    <if condition="$data['city_id'] eq $vo['area_id']">selected="selected"</if>
                    >{BEESCRM:$vo['area_name']}</option>
                </volist>
            </select>
            <span class="triangle"></span>
        </p>

        <p class="title">所在县区</p>
        <p class="form-box">
            <select class="select" id="district">
                <option value="0">请选择县区</option>
                <volist name="district" id="vo">
                    <option value="{BEESCRM:$vo['area_id']}"
                    <if condition="$data['district_id'] eq $vo['area_id']">selected="selected"</if>
                    >{BEESCRM:$vo['area_name']}</option>
                </volist>
            </select>
            <span class="triangle"></span>
        </p>

        <p class="title">详细地址</p>
        <p class="form-box">
            <input class="input" value="{BEESCRM:$data.address_detail}" id="addressDetail"/>
        </p>
    </if>

    <div class="marginb-50"></div>
    <div class="btn-box">
        <input type="hidden" id="store_id" value="{BEESCRM:$storeId}">
        <input type="hidden" id="address_id" value="{BEESCRM:$address_id}">
        <input type="hidden" id="picked" value="{BEESCRM:$picked}">
        <input type="hidden" id="user_type_container" value="{BEESCRM:$userType}" />
        <input type="hidden" id="account_id_container" value="{BEESCRM:$accountId}" />
        <a href="javascript:void(0)" class="btn big" id="addAddr">提交</a>
    </div>
</div>

<include file="../Address/commonJS"/>
<script src="/assets/store/js/address_together.js"></script>
<script>
    $('#addAddr').on('click', function () {
        /*var order_id=$('#order_id').val();*/
        var address_id = $('#address_id').val();
        var real_name = $('#real_name').val();
        var mobile = $('#mobile').val();
        var verify_method = /1[3|4|5|7|8][0-9]{9}/;
        var picked = $('#picked').val();
        var userType = $('#user_type_container').val();

        var province_id = $("#province").val();
        var province_name = $("#province").find("option:selected").text();
        var city_id = $("#city").val();
        var city_name = $("#city").find("option:selected").text();
        var district_id = $("#district").val();
        var district_name = $("#district").find("option:selected").text();

        var address_detail = $("#addressDetail").val();
        //var account_id = $('#account_id_container').val();

        if (real_name == '') {
            $.alert('error', '请输入姓名');
            return false;
        }else if (!verify_method.test(mobile)) {
            $.alert('error', '请输入正确的手机号');
            return false;
        } else {
            if (picked != 1 ) {
                if (!province_id) {
                    $.alert('error', '请选择省份');
                    return false;
                } else if (!city_id) {
                    $.alert('error', '请选择城市');
                    return false;
                } else if (!district_id) {
                    $.alert('error', '请选县区');
                    return false;
                } else if (address_detail == '') {
                    $.alert('error', '请输入详细地址');
                    return false;
                }
            }
            var data = {
                'address_id': address_id,
                'real_name': real_name,
                'mobile': mobile,
                'picked': picked,
                'userType' : userType,
                'address_detail' : address_detail,
                'province_id':province_id,
                'province_name':province_name,
                'city_id':city_id,
                'city_name':city_name,
                'district_id':district_id,
                'district_name':district_name
            };
            $.ajax({
                url: "{BEESCRM::U('/base/store/addAddress',array('store_id'=>$storeId))}",
                type: 'post',
                data: data,
                dataType: 'json',
                success: function (data) {
                    if (data.status == 'S') {
                        $.alert('success', data.message);
                        setTimeout("location.href ='/base/store/address/store_id/"+ data.store_id +"/picked/" + data.picked + "'", 2000);
                    } else {
                        $.alert('error', data.message);
                        return false;
                    }
                }
            });
        }
    });
</script>
</body>

</html>
